package com.wyait.manage.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wyait.manage.dao.AboutMapper;
import com.wyait.manage.pojo.About;
import com.wyait.manage.pojo.Article;
import com.wyait.manage.utils.PageDataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * 文章service
 */


@Service
public class AboutServiceImpl implements AboutService{
    @Autowired(required = false)
    private AboutMapper aboutMapper;


    @Override
    public PageDataResult getAboutInfo(About about, Integer page, Integer limit) {

        PageDataResult pdr = new PageDataResult();
        PageHelper.startPage(page, limit);
        List<About> abouts = aboutMapper.getAboutInfo(about);
        // 获取分页查询后的数据
        PageInfo<About> pageInfo = new PageInfo<>(abouts);
        // 设置获取到的总记录数total：
        pdr.setTotals(Long.valueOf(pageInfo.getTotal()).intValue());
        pdr.setList(abouts);
        return pdr;


    }

    @Override
    public String setAbout(About about) {
        //如果id不为空执行更新操作
        if(about.getId() != null){
            int i = aboutMapper.updateAbout(about);
            if (i != 0){
                return "ok";
            }else{
                return "更新失败";
            }
        }else{
            //否则执行新增操作
            int i = aboutMapper.insert(about);

            if (i != 0){
                return "ok";
            }else{
                return "新增失败";
            }
        }

    }

    @Override
    public String delAbout(Integer id) {
        int i = aboutMapper.delAbout(id);
        if (i != 0){
            return "ok";
        }else{
            return "删除失败";
        }
    }


}
